<?php
// +----------------------------------------------------------------------
// | Copyright (c) 2012 HongPing All rights reserved.
// +----------------------------------------------------------------------
// | ActionName:系统首页
// +----------------------------------------------------------------------
// | Author: HongPing <hongping626@qq.com>
// +----------------------------------------------------------------------
class IndexAction extends CommonAction {

	public function index() {
		if (isset ( $_SESSION [C ( 'USER_AUTH_KEY' )] )) {
			//显示菜单项
			$menu = array ();
			
			//读取数据库模块列表生成菜单项
			$node = M ( "Node" );
			$id = $node->getField ( "id" );
            //echo $node->getLastSql();
			$where ['level'] = 2;
			$where ['status'] = 1;
			$where ['pid'] = $id;
			$list = $node->where ( $where )->field ( 'id,name,group_id,title' )->order ( 'sort asc' )->select ();
			$accessList = $_SESSION ['_ACCESS_LIST'];
			foreach ( $list as $key => $module ) {
				if (isset ( $accessList [strtoupper ( APP_NAME )] [strtoupper ( $module ['name'] )] ) || $_SESSION ['administrator']) {
					//设置模块访问权限
					$module ['access'] = 1;
					$menu [$key] = $module;
				}
			}
			if (! empty ( $_GET ['tag'] )) {
				$this->assign ( 'menuTag', $_GET ['tag'] );
			}
            $stockM = M('stocksview');
            $stockNums = $stockM->sum('stocknums');/*库存数量*/
            $stockAccount = $stockM->sum('stocknums * presale');//库存金额
            
            
            $Userlog	=	M('Userlog');            
            $uid['userid'] = $_SESSION [C ( 'USER_AUTH_KEY' )] ;
            $logList = $Userlog ->where($uid)->order('login_time desc')->limit(8)->select();
            
            $Ordermain = M('Ordermain');
            $startD = strtotime(date('Y-m-d 00:00:00'));
            $endD = strtotime(date('Y-m-d 23:59:59'));
            $Qmap['ordertime']  = array('between',$startD.','.$endD);
            /*进货*/
            $Qmap['ordertype'] = 1;
            $Qlist['phNums'] = $Ordermain->where($Qmap)->sum('ordernums');            
            $Qlist['phAmount'] = $Ordermain->where($Qmap)->sum('payamount');
            /*进货退货*/
            $Qmap['ordertype'] = 2;
            $Qlist['pbNums'] = $Ordermain->where($Qmap)->sum('ordernums');
            //echo $Ordermain->getLastSql();
            $Qlist['pbAmount'] = $Ordermain->where($Qmap)->sum('payamount');
            /*销售*/
            $Qmap['ordertype'] = 3;
            $Qlist['slNums'] = $Ordermain->where($Qmap)->sum('ordernums');
            $Qlist['slAmount'] = $Ordermain->where($Qmap)->sum('payamount');
            /*销售退货*/
            $Qmap['ordertype'] = 4;
            $Qlist['sbNums'] = $Ordermain->where($Qmap)->sum('ordernums');
            $Qlist['sbAmount'] = $Ordermain->where($Qmap)->sum('payamount');
	
            $this->assign ( 'stockNums', $stockNums );
            $this->assign ( 'stockAccount', $stockAccount );
			$this->assign ( 'menu', $menu );
            $this->assign ( 'logList', $logList );
            $this->assign ( 'Qlist', $Qlist );
		}
		$this->display ();
	}

}
?>